
/**
 * title
 * @version  v1.0
 * @createTime: 2017/4/12 0012
 * @createAuthor LSZ
 * @updateHistory
 *                2017/4/12 0012  ashen   create
 */
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    count: 0,
    massage: '',
    aTodos: [{value: '默认默认', id: 0}],
    list: ''
  },
  getters: {
    nCounts (state) {
      return state.aTodos.length
    }
  },
  mutations: {
    increment: state => state.count++,
    decrement: state => state.count--,
    ONADDTODO (state, item) {
      state.aTodos.push(item)
    },
    ONDELTODO (state, index) {
      state.aTodos.splice(index, 1)
    },
    ONERROR (state, str) {
      state.massage = str
    },
    ADDLIST (state, item) {
      state.list = item
    }
  },
  actions: {
    // 提交 ONADDTODO
    onAddTodo (context, item) {
      if (item.value !== '') {
        context.commit('ONADDTODO', item)
        context.commit('ONERROR', '')
      } else {
        context.commit('ONERROR', '添加失败')
      }
    },
    // 提交 ONDELTODO
    onDelTodo ({commit}, index) {
      commit('ONDELTODO', index)
    }
  }
  // strict: process.env.NODE_ENV !== 'production'
})

export default store
